package com.heima.article.controller.v1;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.heima.article.service.AuthorService;
import com.heima.model.article.pojos.ApAuthor;
import com.heima.model.common.dtos.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("api/v1/author")
@Api(value = "app作者管理API",tags = "app作者管理API")
public class ArticleController {

    //注入service
    @Autowired
    AuthorService articleService;

    /**
     * 根据用户id查询作者信息
     * @param id 用户id
     * @return
     */
    @ApiOperation("根据用户id查询作者信息")
    @GetMapping("findByUserId/{id}")
    public ResponseResult findByUserId(@PathVariable("id") Integer id){
        articleService.getOne(Wrappers.<ApAuthor>lambdaQuery().eq(ApAuthor::getUserId,id));
        return ResponseResult.okResult();
    }

    /**
     * 保存作者信息
     * @param apAuthor 封装作者信息的对象
     * @return
     */
    @ApiOperation("保存作者信息")
    @PostMapping("save")
    public ResponseResult save(@RequestBody ApAuthor apAuthor){
        articleService.save(apAuthor);
        return ResponseResult.okResult(apAuthor);
    }


}
